/****************************************************
文件：DSEntity.cs
作者：UnitySir
邮箱：zouajck@foxmail.com
日期：2021/03/22 20:24:37
功能：Nothing
*****************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;

namespace DSFramework
{
    public class DSEntity : MonoBehaviour
    {
        #region InitCmpt

        public static ResourceComponent Resource { get; private set; }
        public static SceneComponent Scene { get; private set; }
        public static DBComponent DB { get; private set; }
        public static AudioComponent Audio { get; private set; }
        public static PoolComponent Pool { get; private set; }
        public static MonoComponent Mono { get; private set; }
        public static MsgMechainComponent MsgMechain { get; private set; }
        public static DebugsComponent Debugs { get; private set; }
        public static PrefsDataComponent PrefsData { get; private set; }

        #endregion

        private void Awake()
        {
            DontDestroyOnLoad(this);
            InitCmpts();
            OnAwake();
        }

        private void Start()
        {
            OnStart();
        }

        private void InitCmpts()
        {
            Transform cmpt = transform.GetChild(0);
            Resource = cmpt.GetComponent<ResourceComponent>();
            DB = cmpt.GetComponent<DBComponent>();
            Audio = cmpt.GetComponent<AudioComponent>();
            Pool = cmpt.GetComponent<PoolComponent>();
            Mono = cmpt.GetComponent<MonoComponent>();
            MsgMechain = cmpt.GetComponent<MsgMechainComponent>();
            Scene = cmpt.GetComponent<SceneComponent>();
            Debugs = cmpt.GetComponent<DebugsComponent>();
            PrefsData = cmpt.GetComponent<PrefsDataComponent>();
        }

        private void OnAwake()
        {
            Mono.InitCmpts();
            Scene.InitCmpts();

            MsgMechain.InitCmpts();

            Resource.InitCmpts();
            Debugs.InitCmpts();
            Pool.InitCmpts();
            DB.InitCmpts();
            Audio.InitCmpts();
            PrefsData.InitCmpts();
        }

        private void OnStart()
        {
        }

        private void OnDestroy()
        {
            Mono.ShutDown();
            MsgMechain.ShutDown();
            Resource.ShutDown();
            Debugs.ShutDown();
            DB.ShutDown();
            Audio.ShutDown();
            Scene.ShutDown();
            Pool.ShutDown();
            Debugs.ShutDown();
            PrefsData.ShutDown();
        }
    }
}